from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
from app01 .utilss.img_code import generate_captcha
import io

@csrf_exempt
def captcha_view(request):
    image, captcha_text = generate_captcha()
    print(captcha_text)
    request.session['captcha_text'] = captcha_text  # 将验证码文本存储在会话中
    buf = io.BytesIO()
    image.save(buf, format='JPEG')
    buf.seek(0)
    return HttpResponse(buf, content_type='image/jpeg')
